package com.mc.stack;
import java.util.Queue;
import java.util.LinkedList;
public class StackQueue {
	
	private Queue<Integer> que1 = new LinkedList<Integer>();
	private Queue<Integer> que2 = new LinkedList<Integer>();
	private boolean flag = true;
	public void push(int value){
		if(flag)
			que1.add(value);
		else
			que2.add(value);
	}
	public int pop(){
		if(flag&&!que1.isEmpty()){
			while(que1.size()>1){
				que2.add(que1.remove());
			}
			flag = false;
			return que1.remove();
		}
		else if(!flag&&!que2.isEmpty()){
			while(que2.size()>1){
				que1.add(que2.remove());
			}
			flag = true;
			return que2.remove();
		}
		return -1;
	}
	public static void main(String[] args) {
		StackQueue sq = new StackQueue();
		sq.push(1);
		sq.push(2);
		sq.push(3);
		sq.push(4);
		sq.push(5);
		System.out.println(sq.pop());
		System.out.println(sq.pop());
		System.out.println(sq.pop());
		System.out.println(sq.pop());
		System.out.println(sq.pop());
		System.out.println(sq.pop());
	}
	
}
